package com.coupons.cmsweb.action;

import java.io.FileInputStream;
import java.io.PrintWriter;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

public class ContentRetrieveServlet extends HttpServlet
{
	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	
	public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException 
	{
		String strlContentId = request.getParameter("contentId");
		//String uid=request.getParameter("uid");
		String pwd=(String)request.getParameter("pwd");
		System.out.println("    "+pwd);
		String strlContent = "";
		PrintWriter out = null;
		response.setContentType("text/xml");
		try{
			out = response.getWriter();	
			strlContent = getContent(strlContentId);					
			out.print(strlContent);
		}catch (Exception e) {
			e.printStackTrace();
			out.print(strlContent);
		}			
	}
	
	public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException 
	{
		doPost(request, response);
	}
	
	
	private String getContent(String straContentId)throws Exception
	{		
		if (null==straContentId || "".equals(straContentId))
		{		
			return "";
		}
		FileInputStream objlInputStream = new FileInputStream("/text/"+straContentId+".txt");
		byte[] buff = new byte[objlInputStream.available()];
		objlInputStream.read(buff);			
		return new String(buff);		
	}

}
